<template>
  <el-dialog draggable overflow :title="titleMap[mode]" v-model="visible" :width="700" destroy-on-close
    @closed="$emit('closed')">
    <sk-tabs type="border-card">
      <el-tab-pane ref="tab" label="信息">
        <el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="right">
          <el-row>
            <el-col :span="22">
              <el-form-item label="编号" prop="code">
                <el-input v-model="form.code" clearable :readonly="form.issystem == 1"></el-input>

              </el-form-item>
            </el-col>
            <el-col :span="22">
              <el-form-item label="名称" prop="name">
                <el-input v-model="form.name" clearable :readonly="form.issystem == 1"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="22">
              <el-form-item label="符合" prop="prefix_unit">
                <el-input v-model="form.prefix_unit" clearable :readonly="form.issystem == 1"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="22">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" clearable :readonly="form.issystem == 1"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </sk-tabs>
    <template v-if="form.issystem == 0" #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>

import skDicSelect from "@/components/skDicSelect";

export default {
  emits: ["success", "closed", "update:modeValue"],
  components: { skDicSelect },
  data() {
    return {

      mode: "add",

      unit: "All",
      titleMap: {
        add: "新增货币",
        edit: "编辑货币",
      },
      form: {
        id: "",
        code: "",
        name: "",
        prefix_unit: "",
        remark: "",
        issystem: 0,
      },
      rules: {
        name: [{ required: true, message: "请输入名称" }],
        code: [{ required: true, message: "请输入编号" }],
        prefix_unit: [{ required: true, message: "请选择符合" }],
      },

      visible: false,
      isSaveing: false,
    };
  },
  mounted() {


  },
  methods: {

    //显示
    close() {
      this.visible = false;
      this.$emit("update:modeValue", false);
      this.$emit("closed");
    },
    open(mode = "add") {
      this.mode = mode;
      this.visible = true;
      return this;
    },

    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;
          var res = await this.$API.basedata.currency.save.post(this.form);
          this.isSaveing = false;
          if (res.code == 200) {
            this.$emit("success", this.form, this.mode);
            this.visible = false;
            this.$message.success("操作成功");
          } else {
            this.$alert(res.message, "提示", { type: "error" });
          }
        }
      });
    },
    //表单注入数据
    setData(data) {
      Object.assign(this.form, data);

    },
  },
};
</script>

<style></style>
